using System;
using System.Collections.Generic;
using System.Text;

using Liberty.Domain.CaseManagement;
using Liberty.Domain.ServiceMemberManagement;
using Liberty.Domain.GrantManagement;

using Microsoft.VisualStudio.TestTools.UnitTesting;
//using NUnit.Framework.SyntaxHelpers;

using Peradigm.Framework.Persistence;

namespace Tests.DomainTests.CaseManagement
{
#if DEBUG
    [TestClass()]
    public class CaseTests : Object
    {
        #region Constants
        private const string
            INJURY_DESCRIPTION = "Test Injury Description",
            SERVICE_MEMBER_FIRST_NAME = "Test Service Member First Name",
            VISIT_ORIGIN_OF_TRAVEL = "Test Visit Origin Of Travel",
            GRANT_DELIVERY_METHOD = "Test Grant Delivery Method";
        private DateTime? TEST_DATE = DateTime.Parse( "05/05/2005" );
        #endregion

        #region SetUp and TearDown TaskTests
        [TestInitialize()]
        public void SetUpCaseTests()
        {
        }

        [TestCleanup()]
        public void TearDownCaseTests()
        {
        }
        #endregion

        #region Test Methods
        [TestMethod()]    
        public void TestProperties()
        {
            Case aCase = Case.TestInstance();
            aCase.DateOfInjury = TEST_DATE;
            Assert.AreEqual( TEST_DATE, aCase.DateOfInjury );

            List<Injury> injuries = new List<Injury>();            
            aCase.AddInjury( new Injury( PersistentModel.NEW_OID, PersistentModel.NEW_VERSION, new TypeOfInjury( INJURY_DESCRIPTION, TypeOfInjury.DEFAULT_RANKING, true ) ) );
            List<Injury> injuriesTest = (List<Injury>)aCase.Injuries;             
            Assert.AreEqual( INJURY_DESCRIPTION, injuriesTest[1].TypeOfInjury.Description );

            ServiceMember aServiceMember = new ServiceMember();
            aServiceMember.FirstName = SERVICE_MEMBER_FIRST_NAME;
            aServiceMember.AddCase( aCase );
            Assert.AreEqual( SERVICE_MEMBER_FIRST_NAME, aCase.ServiceMember.FirstName );

            Visit aVisit = Visit.TestInstance();
            aVisit.OriginOfTravel = VISIT_ORIGIN_OF_TRAVEL;
            aCase.AddVisit( aVisit );
            Assert.AreEqual( 1, new List<Visit>( aCase.Visits ).Count );
            //Assert.That( aCase.Visits[0].OriginOfTravel, Is.EqualTo( VISIT_ORIGIN_OF_TRAVEL ) );

            Grant aGrant = new Grant();
            aGrant.DeliveryMethod = DeliveryMethod.TestInstance();
            aCase.AddGrant( aGrant );
            Assert.AreEqual( 2, new List<Grant>( aCase.Grants ).Count );
            Grant firstGrant = null;
            foreach( Grant grant in aCase.Grants )
            {
                firstGrant = grant;
                break;
            }
            Assert.AreEqual( DeliveryMethod.TestInstance(), firstGrant.DeliveryMethod );
        }
        
        [TestMethod()]
        public void TestAddToVisits_ExpectSuccessfulAdd()
        {
            Case aCase = new Case();
            Assert.IsNotNull( aCase.Visits );
            Assert.AreEqual( 0, new List<Visit>( aCase.Visits ).Count );
            aCase.AddVisit( Visit.TestInstance() );
            Assert.AreEqual( 1, new List<Visit>( aCase.Visits ).Count );
            aCase.AddVisit( Visit.TestInstance() );
            Assert.AreEqual( 2, new List<Visit>( aCase.Visits).Count );
        }

        [TestMethod()]
        public void TestAddGrantToCase()
        {
            Grant aGrant = new Grant();
            Case aCase = new Case();

            Assert.IsNull( aGrant.Case );
            Assert.AreEqual( 0, new List<Grant>( aCase.Grants ).Count );

            aCase.AddGrant( aGrant );

            Assert.IsNotNull( aGrant.Case );
            Assert.AreEqual( 1, new List<Grant>( aCase.Grants ).Count );
            Assert.AreEqual( aCase, aGrant.Case );
        }

        [TestMethod()]
        public void TestAddGrantTwice()
        {
            Case aCase = new Case();
            Grant grant = new Grant();

            aCase.AddGrant( grant );
            aCase.AddGrant( grant );

            Assert.IsNotNull( grant.Case );
            Assert.AreEqual( 1, new List<Grant>( aCase.Grants ).Count );
            Assert.AreEqual( aCase, grant.Case );
        }
        #endregion

        #region Support Methods
        #endregion

        #region Data Elements
        #endregion

    }
#endif
}
